package com.training.ui;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;

import com.training.Service.EmployeeService;
import com.training.dto.EmployeeDTO;

@ManagedBean
public class RegistrationBean {

	@ManagedProperty(value = "#{employeeService}")
	EmployeeService employeeService;

	private String employeeLoginName;
	private String employeeId;
	private String employeeFirstName;
	private String employeeLastName;

	private EmployeeDTO employeeDTO;

	public EmployeeService getEmployeeService() {
		return employeeService;
	}

	public void setEmployeeService(EmployeeService employeeService) {
		this.employeeService = employeeService;
	}

	public String getEmployeeLoginName() {
		return employeeLoginName;
	}

	public void setEmployeeLoginName(String employeeLoginName) {
		this.employeeLoginName = employeeLoginName;
	}

	public String getEmployeeId() {
		return employeeId;
	}

	public void setEmployeeId(String employeeId) {
		this.employeeId = employeeId;
	}

	public String getEmployeeFirstName() {
		return employeeFirstName;
	}

	public void setEmployeeFirstName(String employeeFirstName) {
		this.employeeFirstName = employeeFirstName;
	}

	public String getEmployeeLastName() {
		return employeeLastName;
	}

	public void setEmployeeLastName(String employeeLastName) {
		this.employeeLastName = employeeLastName;
	}

	public EmployeeDTO getEmployeeDTO() {
		return employeeDTO;
	}

	public void setEmployeeDTO(EmployeeDTO employeeDTO) {
		this.employeeDTO = employeeDTO;
	}

	public String saveEmployee() {

		employeeDTO = new EmployeeDTO();
		employeeDTO.setEmployeeId(Integer.valueOf(employeeId).intValue());
		employeeDTO.setFirstName(employeeFirstName);
		employeeDTO.setLastName(employeeLastName);
		employeeDTO.setUserName(employeeLoginName);
		if (employeeService.saveNewEmployee(employeeDTO)) {
			return "index";
		}

		return null;
	}

}
